﻿using System;
using ValidationEngine.Commons.Enums;
namespace ValidationEngine.Commons
{
    /// <summary>
    /// ValidationMgr interface
    /// </summary>
    public interface IValidationProvider
    {
        /// <summary>
        /// Returns registered validator for model type
        /// </summary>
        /// <typeparam name="TModelType">Model type</typeparam>
        /// <returns>Instance of validator if found. NULL other way.</returns>
        IValidator GetValidator<TModelType>() where TModelType : IValidateableModel;
        
        /// <summary>
        /// Registers validator for model type.
        /// </summary>
        /// <typeparam name="TModelType">Model type</typeparam>
        /// <param name="validator">Validator instance</param>
        void RegisterValidator<TModelType>(IValidator validator);
        
        /// <summary>
        /// Validates model instance.
        /// </summary>
        /// <param name="ctx">Validation context</param>
        /// <returns>Model with validation results</returns>
        IValidateableModel ValidateModel(RuleApplingContext ctx = RuleApplingContext.Always);

        /// <summary>
        /// Validates any model
        /// </summary>
        /// <param name="model">Model to validate</param>
        /// <param name="ctx">Validation context</param>
        /// <returns>Model with validation results</returns>
        IValidateableModel ValidateModel(IValidateableModel model, RuleApplingContext ctx = RuleApplingContext.Always);
        
        /// <summary>
        /// View to show validation results on.
        /// </summary>
        IBindableView View { set; }

        /// <summary>
        /// Model to validate
        /// </summary>
        IValidateableModel Model { set; }

        /// <summary>
        /// Indicates if model is valid
        /// </summary>
        bool IsModelValid { get; }
    }
}
